/**
 * 
 */
package com.wjk.service.book.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.wjk.domain.book.Book;
import com.wjk.service.book.BookService;

/**
 *
 * <br>
 *
 * @author wanjk@c-platform.com
 *
 *         <p>
 * @date 创建时间：2018年5月29日:下午11:50:41
 *       </p>
 *
 *       Book business layer
 * 
 */
@Service
public class BookServiceImpl implements BookService {

	private static Map<Long, Book> BOOK_DB = new HashMap<Long, Book>();

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.wjk.service.book.BookService#findAll()
	 */
	@Override
	public List<Book> findAll() {
		return new ArrayList<Book>(BOOK_DB.values());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.wjk.service.book.BookService#insertByBook(com.wjk.domain.book.Book)
	 */
	@Override
	public Book insertByBook(Book book) {
		book.setId(BOOK_DB.size() + 1L);
		BOOK_DB.put(book.getId(), book);
		return book;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.wjk.service.book.BookService#update(com.wjk.domain.book.Book)
	 */
	@Override
	public Book update(Book book) {
		Long bookId =book.getId();
		BOOK_DB.put(bookId, book);
		return book;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.wjk.service.book.BookService#delete(com.wjk.domain.book.Book)
	 */
	@Override
	public Book delete(Book book) {
		BOOK_DB.remove(book.getId());
		return book;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.wjk.service.book.BookService#findById(com.wjk.domain.book.Book)
	 */
	@Override
	public Book findById(Long id) {
		return BOOK_DB.get(id);
	}

}
